import { MyLogger } from './mylogger.bundle';
import { AppServer } from './server.bundle';
import * as path from 'path';
import * as child_process from 'child_process';
import * as express from 'express';
var app = express();
var logger = new MyLogger(false).logger;

app.use(express.static(path.join(__dirname, '/dist/ngterm/')));
app.get('/', (req, res) => {
    res.sendFile(path.join(__dirname, '/dist/ngterm/index.html'));
});
var port = 3000;
if (process.argv.length > 2) port = parseInt(process.argv[2]);
var appServer = new AppServer(app, port, logger, (localport) => {
    logger.info("The server is running at localhost:", localport);
    setTimeout(() => {
        if (!appServer.hasConn) child_process.exec('start http://127.0.0.1:' + localport);
    }, 3000)
})